/*
 * @Author: szx
 * @Date: 2022-03-16 13:48:58
 * @LastEditTime: 2022-03-16 13:52:46
 * @Description:
 * @FilePath: \leetcode\100-199\122\122_2.js
 */
/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
    let res = 0;
    for (let i = 0; i < prices.length - 1; i++) {
        if (prices[i + 1] - prices[i] > 0) {
            res += prices[i + 1] - prices[i];
        }
    }
    return res;
};
console.log(maxProfit([7, 1, 5, 3, 6, 4]));
